home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / interp / bool.c next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.7 KB  |  102 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: bool.c,v 1.5 94/10/05 20:57:39 nkramer Exp $
  27. *
  28. * This file implements the booleans, #t and #f.
  29. *
  30. \**********************************************************************/
  31.  
  32. #include "../compat/std-c.h"
  33.  
  34. #include "mindy.h"
  35. #include "print.h"
  36. #include "gc.h"
  37. #include "class.h"
  38. #include "obj.h"
  39. #include "bool.h"
  40.  
  41. struct bool {
  42.     obj_t class;
  43. };
  44.  
  45. obj_t obj_True = 0, obj_False = 0, obj_BooleanClass = 0;
  46.  
  47.  
  48. /* Printer support. */
  49.  
  50. static void print_true(obj_t true)
  51. {
  52.     printf("#t");
  53. }
  54.  
  55. static void print_false(obj_t false)
  56. {
  57.     printf("#f");
  58. }
  59.  
  60.  
  61. /* GC support. */
  62.  
  63. static int scav_bool(struct object *bool)
  64. {
  65.     return sizeof(struct bool);
  66. }
  67.  
  68. static obj_t trans_bool(obj_t bool)
  69. {
  70.     return transport(bool, sizeof(struct bool));
  71. }
  72.  
  73. void scavenge_bool_roots(void)
  74. {
  75.     scavenge(&obj_True);
  76.     scavenge(&obj_False);
  77.     scavenge(&obj_BooleanClass);
  78. }
  79.  
  80.  
  81. /* Init stuff. */
  82.  
  83. void make_bool_classes(void)
  84. {
  85.     obj_BooleanClass = make_abstract_class(TRUE);
  86.     obj_True = alloc(make_builtin_class(scav_bool, trans_bool),
  87.              sizeof(struct bool));
  88.     obj_False = alloc(make_builtin_class(scav_bool, trans_bool),
  89.               sizeof(struct bool));
  90. }
  91.  
  92. void init_bool_classes(void)
  93. {
  94.     init_builtin_class(obj_BooleanClass, "<boolean>", obj_ObjectClass, NULL);
  95.     init_builtin_class(obj_ptr(struct bool *, obj_True)->class,
  96.                "<true>", obj_BooleanClass, NULL);
  97.     def_printer(obj_ptr(struct bool *, obj_True)->class, print_true);
  98.     init_builtin_class(obj_ptr(struct bool *, obj_False)->class,
  99.                "<false>", obj_BooleanClass, NULL);
  100.     def_printer(obj_ptr(struct bool *, obj_False)->class, print_false);
  101. }
  102.